package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.generator.entity.ZbbChartEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.ZbbChartDao;
import io.renren.modules.generator.service.ZbbChartService;


@Service("zbbChartService")
@DataSource("slave1")
public class ZbbChartServiceImpl extends ServiceImpl<ZbbChartDao, ZbbChartEntity> implements ZbbChartService {


    @Autowired
    ZbbChartDao zbbChartDao;
    @DataSource("slave1")
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ZbbChartEntity> page = this.page(
                new Query<ZbbChartEntity>().getPage(params),
                new QueryWrapper<ZbbChartEntity>()
        );

        return new PageUtils(page);
    }

    @DataSource("slave1")
    @Override
    public ZbbChartEntity getById(Integer id) {
        ZbbChartEntity zbbChartEntity = zbbChartDao.selectById(id);
        return zbbChartEntity;
    }

    @Override
    @DataSource("slave1")
    public boolean save(ZbbChartEntity entity) {
        entity.setCreateTime(new Date());
        return SqlHelper.retBool(zbbChartDao.insert(entity));
    }


    @DataSource("slave1")
    @Override
    public boolean updateById(ZbbChartEntity zbbChart) {
        return SqlHelper.retBool(zbbChartDao.updateById(zbbChart));
    }

    @DataSource("slave1")
    @Override
    public boolean removeByIds(List idList) {
        return CollectionUtils.isEmpty(idList) ? false : SqlHelper.retBool(zbbChartDao.deleteBatchIds(idList));
    }

}